#!/bin/bash
# Copyright (c) 2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# Fix code formatting issues.

source "$(dirname "$0")/common_lib.sh"
init_py_env

# Python
black taihe tests
ruff check taihe tests --fix

# Cpp, runtime
find ../runtime/include ../runtime/src -type f |
    clang-format --verbose -i @/dev/stdin

# Cpp, tests
find ../test ../cookbook \
    \( -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp' \) \
    -not -path '*generated*' -type f |
    clang-format --verbose -i @/dev/stdin

# ArkTS
find ../test ../cookbook -name '*.ets' -type f -print0 | while IFS= read -r -d $'\0' file; do
    clang-format --assume-filename main.js <"$file" >"${file}.formatted" && mv "${file}.formatted" "$file"
done
